package com.lrkj.system.controller;

import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.domain.entity.OrgTree;
import com.lrkj.system.service.IOrgTreeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 组织树Controller
 *
 * @author yajun_ren
 * @date 2021-07-28
 */
@RestController
@RequestMapping("/system/orgTree")
public class OrgTreeController extends BaseController {
    @Autowired
    private IOrgTreeService orgTreeService;

    /**
     * 查询组织树列表
     */
    @ApiOperation(value = "查询组织树列表", notes = "查询组织树列表")
    @GetMapping("/list")
    public AjaxResult list(OrgTree orgTree) {
        List<OrgTree> list = orgTreeService.selectOrgTreeList(orgTree);
        return AjaxResult.success(list);
    }


    /**
     * 获取组织树详细信息
     */
    @ApiOperation(value = "获取组织树详细信息", notes = "获取组织树详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(orgTreeService.selectOrgTreeById(id));
    }

    /**
     * 获取机构下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(OrgTree orgTree) {
        List<OrgTree> depts = orgTreeService.selectOrgTreeList(orgTree);
        return AjaxResult.success(orgTreeService.buildDeptTreeSelect(depts));
    }

    /**
     * 根据子节点获取所有父类节点名称
     */
    @GetMapping(value = "/parentNames/{id}")
    public AjaxResult parentNames(@PathVariable("id") String id) {
        return AjaxResult.success(orgTreeService.parentNames(id));
    }


}
